<script setup>
import { ref } from 'vue'
import request from '@/api/request.js'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import {userLoginApi} from "@/api/UserApi.js";

const form = ref({
  username: '',
  pwd: ''
})
const router = useRouter()
//登录方法
const login = async () => {
  //访问后台
  const res = await userLoginApi(form.value)
  if (res.code == 1) {
    ElMessage({
      type: "error",
      message: "用户名或密码错误"
    })
  } else {
    ElMessage({
      type: 'success',
      message: '操作成功'
    })
    //改变路由地址，跳转到成功页面
    router.push('/index')
  }
}
</script>

<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="用户名">
      <el-input v-model="form.username" />
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="form.pwd" type="password" />
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="login">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped>

</style>
